<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_categorie_listing.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty();

$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

require_once(DIR_FS_INC.'inc.get_all_get_params.php');
require_once(DIR_FS_INC.'inc.get_vpe_name.php');

require_once(DIR_FS_INC.'inc.get_subcategories.php');
get_subcategories($sub_categories, $current_category_id);

include(DIR_WS_MODULES.'product_filter.php');

$sorting_sql = $db->db_query("SELECT products_sorting, products_sorting2 FROM ".TABLE_CATEGORIES." WHERE categories_id = '".$current_category_id."'");

if(!$sorting_sql->fields['products_sorting'])
	$sorting_sql->fields['products_sorting'] = 'pd.products_name';
	
$sorting = ' ORDER BY '.$sorting_sql->fields['products_sorting'].' '.$sorting_sql->fields['products_sorting2'].' ';

$listing_sql = "SELECT 
					p.products_fsk18,
					p.products_shippingtime,
					p.products_model,
					p.products_ean,
					pd.products_name,
					m.brand_name,
					p.products_quantity,
					p.products_image,
					p.products_weight,
					pd.products_short_description,
					pd.products_description,
					p.products_id,
					p.brand_id,
					p.products_price,
					p.products_vpe,
					p.products_vpe_status,
					p.products_vpe_value,                             
					p.products_discount_allowed,
					p.products_tax_class_id
				FROM 
					".TABLE_PRODUCTS_DESCRIPTION." pd, 
					".TABLE_PRODUCTS_TO_CATEGORIES." p2c, 
					".TABLE_PRODUCTS." p 
					LEFT JOIN ".TABLE_BRAND." m ON p.brand_id = m.brand_id
					LEFT JOIN ".TABLE_SPECIALS." s ON p.products_id = s.products_id
				WHERE 
					p.products_status = '1'
				AND 
					p.products_id = p2c.products_id
				AND
				 	pd.products_id = p2c.products_id
					".$group_check_p.$fsk_lock.$filter_products."                             
				AND 
					pd.language_id = '".(int)$_SESSION['languages_id']."'
				AND 
					p2c.categories_id = '".$current_category_id."' ".$sorting;

#p2c.categories_id IN (".implode(",", $sub_categories).")".$sorting;

$listing = new page_break($listing_sql, $_GET['page'], true, 'index.php', 'product_listing');
$module_content = array();
if($listing->result) {
	$rows = 0;
	while(!$listing->sql_string->EOF) { $rows++;
		if($listing->listName == 'mosaic' && empty($listing->sql_string->fields['products_image'])) {}
		else $module_content[] = $product->buildDataArray($listing->sql_string->fields, 'thumbnail', $listing->listData, $rows);
		$listing->sql_string->MoveNext();
	}

	$module_smarty->assign('module_content', $module_content);

	$module_smarty->assign('NAVIGATION', $listing->getLinks());
	$module_smarty->assign('LIST_NAME', $listing->page_name.'_extra');
	$module_smarty->assign('CLASS_NAME', $listing->listName);

	$module_smarty->assign('language', $_SESSION['language']);
	
	include(DIR_WS_MODULES.'page_view_as.php');
	include(DIR_WS_MODULES.'page_per_site.php');
	include(DIR_WS_MODULES.'page_mulit_sort.php');
	include(DIR_WS_MODULES.'page_brand.php');
	
	if(!CacheCheck()) {
		$module_smarty->caching = false;
		$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/'.$listing->listData['list_file'].'.html');

	} else {
		$module_smarty->caching = true;
		$module_smarty->cache_lifetime = CACHE_LIFETIME;
		$module_smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $current_category_id.'_'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_name'].'_'.$_SESSION['currency'].'_'.$_GET['brand'].'_'.$_GET['filter_id'].'_'.$_GET['tag'].'_'.$_GET['page'].'_'.$_GET['keywords'].'_'.$_GET['categories_id'].'_'.$_GET['pfrom'].'_'.$_GET['pto'].'_'.$_GET['x'].'_'.$_GET['y'].'_'.$_GET['per_site'].'_'.$_GET['view_as'];
		$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/'.$listing->listData['list_file'].'.html', $cache_id);
	}

	$default_smarty->assign('MODULE_product_listing', $module);
}
?>